package org.sg20.pagerank.pagerankviewer;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class PageRankViewerMapper extends Mapper<LongWritable, Text, DecFloatWritable, Text> {
    private Text outPerson = new Text();
    private DecFloatWritable outPr = new DecFloatWritable();

    /*
    接受到的格式为 角色 pr|链接到的人物1, 人物2
     */
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, DecFloatWritable, Text>.Context context) throws IOException, InterruptedException {
        String[] thisInput = value.toString().split("\t");
        String[] line = thisInput[1].split("\\|");
        Float pr = Float.parseFloat(line[0]);
        outPerson.set(thisInput[0]);
        outPr.set(pr);
        context.write(outPr, outPerson);
    }
}
